home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SATAN11.ZIP / SRC / BOOT / BOOT.C next >
Encoding:
C/C++ Source or Header  |  1995-03-07  |  2.5 KB  |  79 lines

  1.  /*
  2.   * Usage: boot bootclient bootserver
  3.   * 
  4.   * Executes a bootparam WHOAMI request and print the results.
  5.   */
  6.  
  7. #include <stdio.h>
  8. #include <sys/types.h>
  9. #include <sys/socket.h>
  10. #include <netdb.h>
  11. #include <rpc/rpc.h>
  12. #include "bootparam_prot.h"
  13.  
  14. main(argc, argv)
  15. int     argc;
  16. char   *argv[];
  17. {
  18.     int     stat;
  19.     char    host[256];
  20.     struct hostent *hp;
  21.     static struct bp_whoami_arg bp_arg;
  22.     static struct bp_whoami_res bp_res;
  23.     char   *domain;
  24.     char   *strchr();
  25.     char   *clnt_sperrno();
  26.     char   *me = argv[0];
  27.     char   *client = argv[1];
  28.     char   *server = argv[2];
  29.     long    addr;
  30.  
  31.     if (argc != 3) {
  32.     fprintf(stderr, "Usage: %s bootclient bootserver\n", me);
  33.     exit(1);
  34.     }
  35.     /* Find out the bootserver's official host name. */
  36.     if ((hp = gethostbyname(server)) == NULL) {
  37.     fprintf(stderr, "Host %s not found.\n", server);
  38.     exit(1);
  39.     }
  40.     /* If bootclient name isn't in FQDN form, append domain from server. */
  41.     if (strchr(client, '.') == 0 && (domain = strchr(hp->h_name, '.')) != 0) {
  42.     sprintf(host, "%s%s", client, domain);
  43.     client = host;
  44.     }
  45.     /* Find out the bootclient's address. Assume it has only one. */
  46.     if ((hp = gethostbyname(client)) != NULL) {
  47.     memcpy((caddr_t) & bp_arg.client_address.bp_address_u.ip_addr,
  48.            hp->h_addr_list[0], hp->h_length);
  49.     } else if ((addr = inet_addr(client)) != -1) {
  50.     memcpy((caddr_t) & bp_arg.client_address.bp_address_u.ip_addr,
  51.            &addr, sizeof(addr));
  52.     } else {
  53.     fprintf(stderr, "Host %s not found.\n", client);
  54.     return (1);
  55.     }
  56.     bp_arg.client_address.address_type = IP_ADDR_TYPE;
  57.     bp_res.client_name = 0;            /* allocate buffer */
  58.     bp_res.domain_name = 0;            /* allocate buffer */
  59.  
  60.     if (stat = callrpc(server,
  61.                BOOTPARAMPROG, BOOTPARAMVERS,
  62.                BOOTPARAMPROC_WHOAMI,
  63.                xdr_bp_whoami_arg, &bp_arg,
  64.                xdr_bp_whoami_res, &bp_res)) {
  65.     fprintf(stderr,
  66.         "me: cannot contact bootparam server at %s for %s: %s\n",
  67.         server, client, clnt_sperrno(stat));
  68.     return (1);
  69.     }
  70.     printf("client_name: %s\n", bp_res.client_name);
  71.     printf("domain_name: %s\n", bp_res.domain_name);
  72.     printf("router_addr: %d.%d.%d.%d\n",
  73.        (bp_res.router_address.bp_address_u.ip_addr.net & 0377),
  74.        (bp_res.router_address.bp_address_u.ip_addr.host & 0377),
  75.        (bp_res.router_address.bp_address_u.ip_addr.lh & 0377),
  76.        (bp_res.router_address.bp_address_u.ip_addr.impno & 0377));
  77.     return (0);
  78. }
  79.